package graphics;

import java.util.ArrayList;
import java.util.Iterator;

public class Actor {
	public	Matrix				tmatrix			= null;
	public	Shape				shape			= null;
	public	Wire				wire			= null;
	public	ArrayList<Actor>	children		= new ArrayList<Actor>();
	public	Actor				parent			= null;
	public	boolean				childrenFirst	= false;
	
	public static final class Templates {
		public	static final Actor	box(float radius)							{	return  new Actor(Shape.box(Vector.origon(), radius));	}
		public	static final Actor	axis(float radius)							{	return	new Actor(Shape.axis(radius));					}
		public	static final Actor	triangle(Vector V1, Vector V2, Vector V3)	{	return	new Actor(Shape.triangle(V1, V2, V3));			}
	}
	
	public synchronized void draw(Graphics3D G) {
		G.push(tmatrix);
		
		if (!childrenFirst && shape!=null) {
			G.renderShape(shape);
		}
		
		Iterator<Actor>	itr = children.iterator();
		while(itr.hasNext()) {
			Actor	A = itr.next();
			A.draw(G);
		}
		
		if (childrenFirst && shape!=null) {
			G.renderShape(shape);
		}
		
		G.pop();
	}
	
	
	public Actor(Shape shape) {
		this.tmatrix	= Matrix.identity();
		this.shape		= shape;
		children		= new ArrayList<Actor>();
		parent			= null;
		childrenFirst	= false;
	}
	
}
